﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using System.IO;

namespace ICeFramework.Addin.Utilities
{
    public static class Utilities
    {
        public static string GetNSByProjectItem(Project project, ProjectItem item)
        {
            if (item == null)
            {
                return project.Name;
            }
            DirectoryInfo prjDir = new DirectoryInfo(item.ContainingProject.FullName).Parent;

            DirectoryInfo itemFile = new DirectoryInfo(item.get_FileNames(1));

            string ns = itemFile.Name;
            while (itemFile.FullName != itemFile.Root.FullName && itemFile.FullName != prjDir.FullName)
            {
                itemFile = itemFile.Parent;
                ns = string.Format("{0}.{1}", itemFile.Name, ns);
            }
            return ns;
        }
    }
}
